package com.dify.tool.controller;


import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dify.tool.api.dto.TenderRecordDTO;
import com.dify.tool.api.vo.TenderRecordStatisticsVO;
import com.dify.tool.api.vo.TenderRecordVO;
import com.dify.tool.common.constant.ErrorStatus;
import com.dify.tool.common.model.DefaultResponse;
import com.dify.tool.service.ITenderRecordService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 招标智能体相关接口 前端控制器
 * </p>
 *
 * @author shl
 * @since 2025-05-30
 */
@Slf4j
@RestController
@RequestMapping("/tender")
@Tag(description = "tender", name = "招标智能体相关接口")
public class TenderController {

    @Resource
    private ITenderRecordService iTenderRecordService;

    /**
     * 招标信息记录查询
     */
    @GetMapping("/pageList")
    @Operation(summary = "招标信息记录查询")
    public DefaultResponse<IPage<TenderRecordVO>> pageList(@ParameterObject Page page, @ParameterObject TenderRecordDTO query) {
        return DefaultResponse.success(iTenderRecordService.pageList(page, query));
    }


    /**
     * 招标信息记录统计
     */
    @GetMapping("/statistics")
    @Operation(summary = "招标信息记录统计")
    public DefaultResponse<TenderRecordStatisticsVO> statistics(@ParameterObject TenderRecordDTO query) {
        return DefaultResponse.success(iTenderRecordService.statistics(query));
    }

    /**
     * 技术方案生成
     */
    @GetMapping("/technicalSolutionGenerate/{id}")
    @Operation(summary = "技术方案生成")
    public DefaultResponse<String> technicalSolutionGenerate(@PathVariable("id") Long id) {
        String url = iTenderRecordService.technicalSolutionGenerate(id);
        if (ObjectUtil.isNotEmpty(url)) {
            return DefaultResponse.success(url);
        } else {
            return DefaultResponse.fail(ErrorStatus.GENERATE_FILE_FAILED);
        }
    }

    /**
     * 通过文件ID获取临时访问链接地址
     */
    @GetMapping("/getFileUrlByFileId/{fileId}/{extension}")
    @Operation(summary = "通过文件ID获取临时访问链接地址")
    public DefaultResponse<String> getFileUrlByFileId(@PathVariable("fileId") String fileId, @PathVariable("extension") String extension) {
        return DefaultResponse.success(iTenderRecordService.getFileUrlByFileId(fileId, extension));
    }
}
